//
//  ZXNavigationController.m
//  ZXOCWeiBo
//
//  Created by mac on 15/11/29.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZXNavigationController.h"
//#import "ZXTabbar.h"

@interface ZXNavigationController ()


@end

@implementation ZXNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置导航条背景 全局的
    UINavigationBar * navBar = [UINavigationBar appearance];
    [navBar setBackgroundImage:[UIImage imageNamed:@"adf"] forBarMetrics:UIBarMetricsDefault];
    
    //设置导航条标题
    NSShadow * shadow = [[NSShadow alloc]init];
    shadow.shadowOffset = CGSizeMake(0, 0);
    
    //设置文字大小和阴影NSShadowAttributeName
    NSDictionary * attr = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSShadowAttributeName:shadow};
    [navBar setTitleTextAttributes:attr];
}
/**
 *  每当推出一个导航控制器的时候都会调用这个方法
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//    MethodLog
    
    

    
    //1.获得导航控制器的子控制器的个数
    NSInteger navChildCount = self.viewControllers.count;
//    NSLog(@"=====%ld",navChildCount);
    if (navChildCount > 0)
    {
        //隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem barBtnItemWithNmlImg:@"navigationbar_more" hltImg:@"navigationbar_more_highlighted" target:self action:@selector(backRootVc)];
    }
    
    
    if (navChildCount == 1)
    {
        //获得上一个控制器
     UIViewController * previousVc = self.viewControllers[0];
        NSString * backTitle = previousVc.title;
        
        //设置当前控制器的标题
      viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithTitle:backTitle target:self action:@selector(back)];
    }
    
    if (navChildCount > 1)
    {
        //设置当前控制器的标题
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem backItemWithTitle:@"返回" target:self action:@selector(back)];
        
    }
    
    
    
    [super pushViewController:viewController animated:animated];
}


-(void)back
{
    //返回上一个控制器
    [self popViewControllerAnimated:YES];
}
/**
 *  返回根控制器
 */
-(void)backRootVc
{
    [self popToRootViewControllerAnimated:YES];
}

@end
